<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <script src="/layui/layui.js"></script>
  <script src="/js/jquery/jquery-3.5.1.js"></script>
  <script src="/js/book/book.js"></script>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/bookList.css">
  <title>规则查询</title>
</head>
<body>
<div >

</div>
<div>
  <table class="layui-hide" id="bookRuleTable" lay-filter="bookRuleTable"></table>
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    <button class="layui-btn layui-btn-sm" lay-event="add">新增规则</button>
    <button class="layui-btn layui-btn-sm" lay-event="checkBtn">校验规则</button>
    <button class="layui-btn layui-btn-sm" lay-event="jsonBtn">json编辑测试</button>
  </div>
</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="switchTpl">
<!--  &lt;!&ndash; 这里的 checked 的状态只是演示 &ndash;&gt;-->
<!--  <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="sexDemo" {{ d.id == 10003 ? 'checked' : '' }}>-->
</script>

<script>
  layui.use('table', function(){
    var table = layui.table;

    //展示已知数据
    table.render({
      elem: '#bookRuleTable'
      ,url: '/book/queryBookRuleList'
      ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
      ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
        title: '提示'
        ,layEvent: 'LAYTABLE_TIPS'
        ,icon: 'layui-icon-tips'
      }]
      ,cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
      ,cols: [

        [ //标题栏
          ,{type:'checkbox'}
          ,{field: 'bookId', title: 'ID', width: 200}
          ,{field: 'bookSourceUrl', title: '书源', width: 200}
          ,{field: 'bookSourceName', title: '书源名称', minWidth: 200}
          ,{field: 'bookSourceGroup', title: '书源分类', minWidth: 200}
          ,{field: 'loginUrl', title: '登录url', width: 200}
          ,{field: 'ruleSearchUrl', title: '搜索url', width: 200}
          ,{field: 'ruleSearchList', title: '搜索列表规则', width: 200, sort: true}
          ,{field: 'ruleSearchName', title: '搜索书名规则', width: 200, sort: true}
          ,{field: 'ruleSearchAuthor', title: '搜索作者规则', width: 200, sort: true}
          ,{field: 'ruleSearchKind', title: '搜索分类规则', width: 200, sort: true}
          ,{field: 'ruleSearchLastChapter', title: '搜索最新章节规则', width: 200, sort: true}
          ,{field: 'ruleSearchCoverUrl', title: '搜索简介规则', width: 200, sort: true}
          ,{field: 'ruleSearchNoteUrl', title: '搜索书籍url正则', width: 200, sort: true}
          ,{field: 'ruleBookUrlPattern', title: '书籍详情url正则', width: 200, sort: true}
          ,{field: 'ruleBookInfoInit', title: '书籍详情预处理规则', width: 200, sort: true}
          ,{field: 'ruleBookName', title: '书名规则', width: 200, sort: true}
          ,{field: 'ruleBookAuthor', title: '作者', width: 200, sort: true}
          ,{field: 'ruleCoverUrl', title: '封面规则', width: 200, sort: true}
          ,{field: 'ruleIntroduce', title: '简介规则', width: 200, sort: true}
          ,{field: 'ruleBookKind', title: '分类规则', width: 200, sort: true}
          ,{field: 'ruleBookLastChapter', title: '最新章节', width: 200, sort: true}
          ,{field: 'ruleChapterUrl', title: '目录url规则', width: 200, sort: true}
          ,{field: 'ruleChapterUrlNext', title: '目录下一页', width: 200, sort: true}
          ,{field: 'ruleChapterList', title: '目录列表规则', width: 200, sort: true}
          ,{field: 'ruleChapterName', title: '目录章节名称', width: 200, sort: true}
          ,{field: 'ruleContentUrl', title: '章节url规则', width: 200, sort: true}
          ,{field: 'ruleContentUrlNext', title: '正文下一页规则', width: 200, sort: true}
          ,{field: 'ruleBookContent', title: '正文规则', width: 200, sort: true}
          ,{field:'sex', title:'是否停用', width:100, templet: '#switchTpl', unresize: true}
          ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
        ]

      ]
      ,page: true
      ,response: {
        statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
      }
      ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
        debugger;
        return {
          "code": res.code, //解析接口状态
          "msg": res.msg, //解析提示文本
          "count": res.count, //解析数据长度
          "data": res.data //解析数据列表
        };
      }

    });

    //头工具栏事件
    table.on('toolbar(bookRuleTable)', function(obj){
      var checkStatus = table.checkStatus(obj.config.id);
      switch(obj.event){
        case 'getCheckData':
          var data = checkStatus.data;
          layer.alert(JSON.stringify(data));
          break;
        case 'getCheckLength':
          var data = checkStatus.data;
          layer.msg('选中了：'+ data.length + ' 个');
          break;
        case 'isAll':
          layer.msg(checkStatus.isAll ? '全选': '未全选');
          break;
        case 'add':
          layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
              type: 2,
              title: '',
              shadeClose: true,
              closeBtn: 0,
              shade: 0.8,
              area: ['1050px', '650px'],
              content: '/alert/book/admin/bookRuleEdit'
            });
          });
          break;
          case 'checkBtn':
            layui.use('layer', function(){
              var layer = layui.layer;
              layer.open({
                type: 2,
                title: '规则校验',
                shadeClose: true,
                closeBtn: 1,
                shade: 0.8,
                area: ['1050px', '600px'],
                content: '/alert/book/admin/checkRule'
              });
            });
            break;
        case 'jsonBtn':
          layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
              type: 2,
              title: 'json测试',
              shadeClose: true,
              closeBtn: 1,
              shade: 0.8,
              area: ['1050px', '600px'],
              content: '/alert/book/admin/jsonTest'
            });
          });
          break;
          //自定义头工具栏右侧图标 - 提示
        case 'LAYTABLE_TIPS':
          layer.alert('这是工具栏右侧自定义的一个图标按钮');
          break;
      };
    });

    //监听行工具事件
    table.on('tool(bookRuleTable)', function(obj){
      var data = obj.data;
      //console.log(obj)
      if(obj.event === 'del'){
        layer.confirm('真的删除行么', function(index){
          obj.del();
          layer.close(index);
        });
      } else if(obj.event === 'edit'){
        layer.prompt({
          formType: 2
          ,value: data.email
        }, function(value, index){
          obj.update({
            email: value
          });
          layer.close(index);
        });
      }
    });
  });

</script>

</body>
</html>